﻿// *************************************************************************************************
// Project: RealSenseLight
// Namespace: RealSenseLight.ViewModels
// File: SpeechSynthesizerViewModel.cs  Author: Peter O'Hanlon
// Copyright © Peter O'Hanlon 2014-2015
// Date: 2015/1/6 19:18
// *************************************************************************************************
using RealSense.Light.CodeContracts;
using RealSense.Light.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RealSenseLight.ViewModels
{
  public class SpeechSynthesizerViewModel : ViewModelBase, RealSenseLight.ViewModels.ISpeechSynthesizerViewModel
  {
    private IEnumerable<string> modules;
    private ISpeechSynthesizer speechSynthesizer;
    private string text = "Text";
    private int rate = 100;
    private int volume = 80;
    private int pitch = 100;

    public SpeechSynthesizerViewModel(ISpeechSynthesizer speechSynthesizer, ISpeechSynthesisDevices devices)
    {
      // Verify the contracts
      this.speechSynthesizer = RuntimeAssert.IsNotNull(speechSynthesizer, "speechSynthesizer");
      RuntimeAssert.IsNotNull(devices, "devices");

      modules = devices.GetDevices();

      speechSynthesizer
        .SetVolume(80)
        .SetSpeechModule(modules.FirstOrDefault())
        .SetPitch(100)
        .SetSpeechRate(80)
        .Say("Hello there.");
    }

    public string Text
    {
      get { return text; }
      set { SetAndNotify(ref text, value); }
    }

    public int Rate
    {
      get { return rate; }
      set { SetAndNotify(ref rate, value); }
    }

    public int Volume
    {
      get { return volume; }
      set { SetAndNotify(ref volume, value); }
    }

    public int Pitch
    {
      get { return pitch; }
      set { SetAndNotify(ref pitch, value); }
    }
  }
}
